package tournament.volleyball;

import java.util.ArrayList;

public class Schedule {
	
	Schedule(){
	}
	
	// Primary function of the Schedule Object. Takes an array of numbers formatted as play orders and an ArrayList of Teams.
	// Returns a reference to the last Rivalry Object, which allows for easy serialization.
	public ArrayList<Rivalry> setupSchedule(int[] playOrder, ArrayList<Team> teams) {
		ArrayList<Rivalry> orderedSets = new ArrayList<Rivalry>();
		
		if(playOrder.length != 0) {
			for(int i=0; i<playOrder.length; i++){
				int team1Index = playOrder[i]/100 -1; // will return 1st part of 3-4 digit decimal number
				int team2Index = playOrder[i]%100 -1; // will return 2nd part of 3-4 digit decimal number
				orderedSets.add(new PoolRivalry(teams.get(team1Index), teams.get(team2Index)));
			}
			
			// below loop attaches games team plays to actual team
			for(int i=0; i<teams.size(); i++){
				teams.get(i).updateTeamWithSetGames(orderedSets);
			}
			
			return orderedSets;
		} else {
			return null;
		}
	}
}
